package org.wu.framework.lazy.database.datasource.proxy.handler;

import org.wu.framework.core.Ordered;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public interface DataSourceHandler  extends Ordered {


    /**
     * <p>Attempts to establish a connection with the data source that
     * this {@code DataSource} object represents.
     *
     * @return  a connection to the data source
     * @throws SQLException if a database access error occurs
     * @throws java.sql.SQLTimeoutException  when the driver has determined that the
     * timeout value specified by the {@code setLoginTimeout} method
     * has been exceeded and has at least tried to cancel the
     * current database connection attempt
     */
    Connection getLazyConnection(DataSource dataSource) throws SQLException;

    /**
     * <p>Attempts to establish a connection with the data source that
     * this {@code DataSource} object represents.
     *
     * @param username the database user on whose behalf the connection is
     *  being made
     * @param password the user's password
     * @return  a connection to the data source
     * @throws SQLException if a database access error occurs
     * @throws java.sql.SQLTimeoutException  when the driver has determined that the
     * timeout value specified by the {@code setLoginTimeout} method
     * has been exceeded and has at least tried to cancel the
     * current database connection attempt
     * @since 1.4
     */
    Connection getLazyConnection(DataSource dataSource, String username, String password)
            throws SQLException;
}
